// 显示用户信息
function showUinfo(){
    $.ajax({
        url:api_path+'user/read',
        type:'post',
        dataType:'json',
        success:function(response){
            data = response.data;
            global_user = data;
            console.log(data)
            var fields = ['nickname','truename','mobile','birthday','email','company','signature'];
            for (var i in fields) {
                var field = fields[i];
                var val = data[field];
                $("#"+field).val(val);

                
                if (val == null || val == '') {
                    val = '&nbsp;';
                }
                $("#info_"+field).html(val);
            }
        }
    });
}

// 修改密码
$(".pwd_btn").on('click',function(){
    var params = $("#pwd_form").serialize();
    $.ajax({
        url:api_path+'user/changePwd',
        data:params,
        type:'post',
        dataType:'json',
        success:function(data){
          console.log(data)
          if (data.code == '2000') {
            cchUtil.message('更新成功');
            showUinfo();
          }else{
            cchUtil.message(data.msg,'danger');
          }
        }
    });
});

// 修改信息
$(".profile_btn").on('click',function(){
    var params = $("#profile_form").serialize();
    $.ajax({
        url:api_path+'user/update',
        data:params,
        type:'post',
        dataType:'json',
        success:function(data){
          console.log(data)
          if (data.code == '2000') {
            cchUtil.message('更新成功');
            showUinfo();
          }else{
            cchUtil.message(data.msg,'danger');
          }
        }
    });
});